

<!-- 用户协议 -->
<template>
	<view class="content"><rich-text :nodes="datas"></rich-text></view>
</template>

<script>
export default {
	components: {},
	data() {
		return {
			icon: {},
			datas: ''
		};
	},
	onLoad(options) {
		let title = '';
		let subhead = '';
		let that = this;
		if (options.type == '1') {
			// 用户协议
			title = '用户协议';
			subhead = 'REGISTRATION_PROTOCOL';
		} else if (options.type == '2') {
			// 隐私政策
			title = '隐私政策';
			subhead = 'PRIVACY_POLICY';
		} else if (options.type == '3') {
			// 会员介绍
			title = '会员介绍';
			subhead = 'MEMBERS_TO_INTRODUCE';
		} else if (options.type == '4') {
			// 售后保障
			title = '售后保障';
			subhead = 'AFTER_SALE';
		} else if (options.type == '5') {
			// 余额充值协议
			title = '余额充值协议';
			subhead = 'BALANCE_RECHARGE_AGREEMENT';
		} else if (options.type == '6') {
			// 水券充值协议
			title = '水券充值协议';
			subhead = 'WATER_RECHARGE_AGREEMENT';
		} else if (options.type == '7') {
			// 礼品卡使用协议
			title = '礼品卡使用协议';
			subhead = 'GIFT_CARD__PROTOCOL';
		} else if (options.type == '8') {
			// 抽奖规则
			title = '抽奖规则';
			subhead = 'LUCKY_RULE';
		} else if (options.type == '9') {
			// 抽奖规则
			title = '玩法介绍';
			subhead = 'GAMEPLAY_INTRODUCTION';
		}
		uni.setNavigationBarTitle({
			title: title
		});
		that.$api.globalUtil.requestAjax({
			url: '/resource/getBySubheadFindResourceApi',
			method: 'POST',
			data: {
				subhead: subhead,
				type: '1'
			},
			success: function(res) {
				that.datas = that.formatRichText(res.data.response.details);
			}
		});
	},
	methods: {
		formatRichText(html) {
			
			html = html || "";
			
			//控制小程序中图片大小
			let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
				match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
				match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
				match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
				return match;
			});
			newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
				match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
				return match;
			});
			// newContent = newContent.replace(/<br[^>]*\/>/gi, '');
			newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin:0 auto;"');
			return newContent;
		}
	}
};
</script>

<style lang="less">
page,
.content {
	background: #f5f5f5;
	height: 100%;
}
</style>



